#!/usr/bin/perl

eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
    if 0; # not running under some shell

eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
    if 0; # not running under some shell

#Copyright (C) 2006-2011 OCS Inventory Developers
#
#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; either version 2
#of the License, or (at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
#USA.
#

use strict;
use warnings;

my $devlib;
foreach (@ARGV) {
    if (/^--devlib$/) {
        print "[info] --devlib are found, Developer mode enabled\n";
        eval "use lib '/home/ap/idcos/ocsinventory-agent/lib';";
    }
}

eval "use Ocsinventory::Agent;";
if ($@) {
    print "Failed to load Ocsinventory::Agent, $@\n";
    print "you can run the agent directly for its source directory ";
    print "with --devlib\n";
    exit 1;
}

eval "Ocsinventory::Agent::run();";
print $@;
__END__

=head1 NAME

ocsinventory-agent - Unified client for OCS-Inventory

=head1 SYNOPSIS

B<ocsinventory-agent> S<[ B<-fhilpruw> ]> S<[ I<--server server> | I<--local /tmp> ]>...

=head1 EXAMPLES

    % ocsinventory-agent --server localhost
    # send an inventory to the OCS server

    % ocsinventory-agent --server http://localhost/ocsinventory2
    # send an inventory over http to a server with a non standard
    # virtual directory

    % ocsinventory-agent --server https://localhost/ocsinventory
    # send an inventory over https to the OCS server

    % ocsinventory-agent --local /tmp
    # write an inventory in the /tmp directory

    % ocsinventory-agent --server localhost --user=toto --password=pw --realm="Restricted Area"
    # send a report to a server protected by a basic authentication
    % ocsinventory-agent --lazy
    # send an inventory only if the a random delay between 0 and PROLOG_FREQ had been run over.

    % ocsinventory-agent --delaytime 60 -d
    # If NO PROLOG_FREQ has been preset, pick a time between execution and --delaytime for the agent to contact the server [default is 3600 seconds]

=head1 DESCRIPTION

F<ocsinventory-agent> creates inventory and send or write them. This agent is the
successor of the former linux_agent which was released with OCS 1.01 and prior. It also
replaces the Solaris/AIX/BSD unofficial agents. The detailed list of supported
Operating System is available in the Wiki.

=over 4

=item F<GNU/Linux>

=item F<Solaris>

=item F<FreeBSD>

=item F<NetBSD>

=item F<OpenBSD>

=item F<AIX>

=item F<MacOSX>

=item F<GNU/kFreeBSD>

=back

=head1 OPTIONS

Most of the options are available in a I<short> form and a I<long> form.  For
example, the two lines below are all equivalent:

    % ocsinventory-agent -s localhost
    % ocsinventory-agent --server localhost

=over 4

=item B<--backend-collect-timeout=SECONDS_BEFORE_KILL>

Time before OCS kills modules processing which don't end before the timeout.

=item B<--basevardir>=I<DIR>

Indicate the place where the agent should store its files.

=item B<-d>, B<--daemon>

Launch ocsinventory-agent in background. Proc::Daemon is needed.

=item B<--debug>

Turn the debug mode on.

=item B<--devlib>

This option is designed for backend module developer. With it enabled, ocsinventry-agent won't try to load the Backend module installed on the system. Instead it will scan the ./lib directory.

=item B<--delaytime=SECONDS_TO_WAIT>

This option defaults to waiting a random() time between 0 and 3600 before initially contacting the server assuming NO PROLOG_FREQ has been set. Once PROLOG_FREQ has been set, it uses that number at the top end of it's random setting. Useful for pre-setting a deployed agent's initial start time (so you don't jam the server all at once, but don't have to wait an hour to make sure the deployment worked).

=item B<-f>, B<--force>

The agent will first contact the server during the PROLOG period. If the server doesn't know the machine or has outdated informations, it will ask for an inventory.
With this option, the agent doesn't run the PROLOG with the server first but directly sends an inventory.

=item B<-i>, B<--info>

Turn the verbose mode on. The flag is ignored if B<--debug> is enable.

=item B<--lazy>

Do not contact the server more than one time during the PROLOG_FREQ and do
an exit if there is nothing to do. Useful if you want to start the agent
script regulary from the crontab but don't want to overload the server.

=item B<-l>, B<--local>=I<DIR>

Write an inventory in the I<DIR> directory. A new file will be created if needed.

=item B<--logfile>=I<FILE>

Log message in I<FILE> and turn off STDERR

=item B<-p>, B<--password>=I<PASSWORD>

Use I<PASSWORD> for an HTTP identification with the server.

=item B<-P>, B<--proxy>=I<PROXY>

Use I<PROXY> to specify a proxy HTTP server. By default, the agent uses HTTP_PROXY environment variable. 

=item B<-r>, B<--realm>=I<REALM>

Use I<REALM> for an HTTP identification with the server. For example, the value can be 'Restricted Area'. You can find it in the login popup of your Internet browser.

=item B<-s>, B<--server>=I<URI>

The uri of the server. If I<URI> doesn't start with http:// or https://, the assume the parameter is a hostname and rewrite it like that:

    % http://servername/ocsinventory

If you want to use https or another virtual directory you need to enter the full path.

B<--server> is ignored if B<--local> is in use.

=item B<--stdout>

Print the inventory on stdout.

    % ocsinventory-agent --stdout > /tmp/report.xml
    # prepare an inventory and write it in the /tmp/report.xml file.
    # A file will be created.

=item B<--scan-homedirs>

Authorized OCS to scan home directories to increase the Virtual Machine inventory.
WARNING: beware with user privacy by using this option because it may encounter private data scans (even if it's not designed for !).

=item B<--ssl>=I<0|1>

Check SSL communications using a certificate.
Set to 0 if you want to disable certificate check or 1 to enable (needs CA certificate path in this case) . Default is set to 1. 

=item B<--ca>=I<FILE>

Path to CA certificate chain file in PEM format, for server SSL certificate validation.
Set to <your server configuration directory>/cacert.pem by default. 

=item B<--tag>=I<TAG>

Mark the machine with the I<TAG> tag. Once the initial inventory is accepted by the server this value is ignored and you've to change the information directly on the server. The server do so in order to centralize the administration of the machine.

=item B<-u> I<USER>, B<--user>=I<USER>

Use I<USER> for the server authentication.

=item B<--version>=I<USER>

Print the version and exit.

=item B<-w> I<DURATION>, B<--wait>=I<DURATION>

Wait before initializing the connexion with the server. If I<DURATION> equal I<server> the agent will use the PROLOG_FREQ of the server to determine the duration of this periode. Exactly like it would had done if it was in --daemon mode.
Else if duration is a numerical value, it will be used directly.

    % ocsinventory-agent --wait 5 --server localhost

=item B<--nosoftware>

Do not inventory the software installed on the machine. B<--nosoft> also
works but is deperecated.

=item B<--nolocal>

Desactivate local mode even if it is set in config file or command line

=back

=head1 CONFIG FILE

The agent try to initialize the settings from the B<ocsinventory-agent.cfg>
config file.

It looks for the file in these directories:

=over

=item /etc/ocsinventory

=item /usr/local/etc/ocsinventory

=item /etc/ocsinventory-agent

=back

=head1 AUTHORS

The maintainer is Guillaume PROTET <guillaume.protet@mortheres.info>

Please read the AUTHORS, Changes and THANKS files to see who is behind OCS
Inventory Agent.

=head1 SEE ALSO

=over 4

=item OCS-Inventory website,

 http://www.ocsinventory-ng.org/

=item LaunchPad project page,

 http://launchpad.net/ocsinventory-unix-agent

=item forum,

 http://forums.ocsinventory-ng.org/

=item and wiki

 http://wiki.ocsinventory-ng.org/

=back

=head1 BUGS

Please, use the forum as much as possible. You can open your own bug tickets.
Patches are welcome. You can also use LaunchPad bugtracker or
push your Bazaar branch on LaunchPad and do a merge request.

=head1 COPYRIGHT

Copyright (C) 2006-2011 OCS Inventory contributors

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

=cut
